<template>
  <div id="app">
    <Header v-if="!isShowLogin" :naviIndex = 'activeIndex' style="position: fixed;z-index: 200;"></Header>
    <!-- <nav>
      <router-link to="/">Home</router-link> |
      <router-link to="/about">About</router-link>
    </nav> -->
    <div class="main">
      <router-view />
      <Footer v-if="!isShowLogin"></Footer>
    </div>
  </div>
</template>
<script>
// @ is an alias to /src
import Header from './components/Header/Header.vue';
import Footer from './components/FooterVue/Footer.vue'
export default {
  data() {
    return {
      isShowLogin: false,
      activeIndex:'1',
    }
  },
  beforeMount(){
    console.log(this.$route);
    if (this.$route.path == '/') {
        this.activeIndex = '1'
      } else if (this.$route.path == '/pressflow') {
        this.activeIndex = '3'
      } else if (this.$route.path == '/comsense') {
        this.activeIndex = '4'
      } else if (this.$route.path == '/detail') {
        this.activeIndex = '4'
      } else if (this.$route.path == '/newbook') {
        this.activeIndex = '5'
      } else if (this.$route.path == '/bookdetail') {
        this.activeIndex = '5'
      } else if (this.$route.path == '/publish') {
        this.activeIndex = '6'
      } else if (this.$route.path == '/company') {
        this.activeIndex = '2'
      } else {

      }
  },
  mounted() {
    
  },
  watch: {
    // 按需加载路由，监听路由变化逻辑处理
    $route(to, from) {
      let _this = this//这里注意一下记得缓存this
      // console.log(to, "路由改变body");
      if (this.$route.path == '/login') {
        this.isShowLogin = true;
      } else {
        this.isShowLogin = false;
      }

      console.log(to, "路由改变body");
      console.log(this.$route.path);
      if (this.$route.path == '/') {
        this.activeIndex = '1'
      } else if (this.$route.path == '/pressflow') {
        this.activeIndex = '3'
      } else if (this.$route.path == '/comsense') {
        this.activeIndex = '4'
      } else if (this.$route.path == '/detail') {
        this.activeIndex = '4'
      } else if (this.$route.path == '/newbook') {
        this.activeIndex = '5'
      } else if (this.$route.path == '/bookdetail') {
        this.activeIndex = '5'
      } else if (this.$route.path == '/publish') {
        this.activeIndex = '6'
      } else if (this.$route.path == '/company') {
        this.activeIndex = '2'
      } else {

      }
    }
  },



  components: {
    Header, Footer
  }
}
</script>

<style>
html,
body {
  width: 100%;
  /* width: 100vw; */
  /* height: 100%; */
  /* min-width: 1920px; */
  margin: 0;
  padding: 0;
}

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.main {
  margin-top: 180px;
  width: 100%;
}
</style>
